package com.lms.collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-06-16 06:54
 * @Description:
 */
public class IteratorDemo {
    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(1, 2, 3, 4);
        ArrayList<Integer> objects = new ArrayList<>();
        objects.addAll(list);
        Iterator<Integer> iterator = objects.iterator();
        iterator.forEachRemaining(System.out::println);
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
            iterator.remove();
        }

    }
}

